package com.cgw.web.address.action;

import java.util.List;

import com.cgw.common.base.BaseAction;
import com.cgw.dmplt.address.dao.CityAreaDao;
import com.cgw.dmplt.address.domain.CityArea;
import com.cgw.dmplt.room.domain.Room;

public class CityAreaAction extends BaseAction {

	private CityArea cityArea;

	private String rootId;
	
	private String street;

	public String getStreet() {
		return street;
	}

	public void setStreet(String street) {
		this.street = street;
	}

	public String getRootId() {
		return rootId;
	}

	public void setRootId(String rootId) {
		this.rootId = rootId;
	}

	public CityArea getCityArea() {
		return cityArea;
	}

	public void setCityArea(CityArea cityArea) {
		this.cityArea = cityArea;
	}

	public String doList() {
		CityAreaDao areaDao = (CityAreaDao) getBean("cityAreaDao");
		try {
			if (cityArea == null) {
				cityArea = new CityArea();
			}
			List<CityArea> roomList = areaDao.listCityArea(cityArea);

		} catch (Exception e) {
			log.error("列表查询出错!", e);
		}
		return SUCCESS;
	}

	public String doQuery() {
		if(rootId==null){
			return "";
		}
		CityAreaDao areaDao = (CityAreaDao) getBean("cityAreaDao");
		List<CityArea> areaList = areaDao.findCityAreaRoot(rootId);
		System.out.println("----------------"+areaList.size());
		setStreet(CreateSellNav(rootId,areaList));
		
		System.out.println("1111111111111111111"+street);
		return SUCCESS;
	}

	public String CreateSellNav(String rootId,List<CityArea> areaList)
	{
		try
		{
			StringBuilder sb = new StringBuilder();

			sb.append("<div class=\"filter_container\">");

				///#region 区域

			String strAreID = rootId;

			if (strAreID.isEmpty())
			{
				sb.append("<div class=\"SearchBar\"><ul><li>区域：</li><li class=\"SearchNoRestrict\">不限</li>");
			}
			else
			{
				sb.append("<div class=\"SearchBar\"><ul><li>区域：<li><a class=\"SearchStrStyle\" onclick=\"requestBlock('');\" href=\"javascript:void(0)\">不限</a></li>");
			}

			for (CityArea info : areaList) {
				if (strAreID.equals(info.getRootId())){
					sb.append(String.format("<li><a class=\"SearchNoRestrict\" onclick=\"requestBlock('%1$s');\" href=\"javascript:void(0)\">%2$s</a></li>", info.getRootId(), info.getAreaName()));
				}
				else
				{
					sb.append(String.format("<li><a class=\"SearchStrStyle\" onclick=\"requestBlock('%1$s');\" href=\"javascript:void(0)\">%2$s</a></li>", info.getRootId(), info.getAreaName()));
				}
			}
			sb.append("</ul></div>");

			sb.append("</div>");

			return sb.toString();
		}
		finally
		{
		}
	}


}
